import { Button, ButtonProps } from 'antd';
import { useRouteLoaderData } from 'react-router-dom';

import { IAuthLoader } from '@/router/AuthLoader';

interface IProps extends ButtonProps {
    auth?: string;
}

const AuthButton = (props: IProps) => {
    /* 数据管理--------------------------------------------------- */
    const data = useRouteLoaderData('layout') as IAuthLoader;
    const { buttonList, userInfo } = data;

    // 有权限 或者 超级管理员
    if (props.auth && (buttonList.includes(props.auth) || userInfo.roleList.includes('655dbedb11c02c8597dce76a'))) {
        return <Button {...props}>{props.children}</Button>;
    }

    // 权限不足或者无权限 不显示按钮
    return <></>;
};
export default AuthButton;
